/**
 * Copyright (C) 2010  Hylke van der Schaaf
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
package hextd.creep;

import hextd.wave.PathfinderWaypoints;
import java.util.HashMap;
import java.util.Map;
import com.usoog.tdcore.creep.Creep;

/**
 * The data used to initialise a HexTD Creep.
 *
 * Also contains a bunch of static methods dealing with creeps types, and creep
 * identification.
 * 
 * @see Creep#init(com.usoog.tdcore.gamestate.GameState, java.lang.Object)
 * @author hylke
 */
public class HexTDCreepData {

	public PathfinderWaypoints path;
	public double delay;
	public long health;
	public Map<String, Long> reward;
	public HexTDCreep.Size size;

	public static enum CreepType {

		BlueBox(CreepBlueBox.type, new CreepBlueBox()),
		FastForward(CreepFastForward.type, new CreepFastForward()),
		GreenPlus(CreepGreenPlus.type, new CreepGreenPlus()),
		HardGrey(CreepHardGrey.type, new CreepHardGrey()),
		HealthyHelix(CreepHealthyHelix.type, new CreepHealthyHelix()),
		PeachyPinata(CreepPeachyPinata.type, new CreepPeachyPinata()),
		ProtectedPink(CreepProtectedPink.type, new CreepProtectedPink()),
		RedRaver(CreepRedRaver.type, new CreepRedRaver()),
		SprintingSalmon(CreepSprintingSalmon.type, new CreepSprintingSalmon()),
		YellorRotor(CreepYellowRotor.type, new CreepYellowRotor());
		private final String name;
		private final HexTDCreep instance;

		CreepType(String name, HexTDCreep instance) {
			this.name = name;
			this.instance = instance;
		}

		/**
		 * @return The two-letter code of the creep
		 */
		public String getName() {
			return this.name;
		}

		public double getPreferredDelay() {
			return this.instance.getPreferredDelay();
		}
	}
	private static final Map<String, CreepType> table;

	static {
		table = new HashMap<String, CreepType>();
		for (CreepType enemy : CreepType.values()) {
			table.put(enemy.getName(), enemy);
		}
		table.put("gg", CreepType.GreenPlus);
	}

	public static boolean isEnemy(String name) {
		return table.containsKey(getNamePart(name));
	}

	public static CreepType identifyEnemy(String name) {
		return table.get(getNamePart(name));
	}

	public static String getNamePart(String name) {
		switch (name.charAt(0)) {
			case 'L':
			case 'S':
			case 'N':
				return name.substring(1);
			default:
				return name;
		}
	}

	public static HexTDCreep.Size getSize(String name) {
		switch (name.charAt(0)) {
			case 'L':
				return HexTDCreep.Size.large;
			case 'S':
				return HexTDCreep.Size.small;
			case 'N':
			default:
				return HexTDCreep.Size.normal;
		}
	}
}
